<!--地址列-->
<style scoped>
.demo-content {
  padding: 10px 10px;
}

.weui-cell {
  padding: 10px 5px !important;
}

</style>
<template>
  <div>
    <div v-if="addressList.length > 0">
      <group>
        <cell-box v-for="address in addressList" :key="address.addressId">
          <swipeout class="vux-1px-tb">
            <swipeout-item transition-mode="follow">
              <div slot="right-menu">
                <swipeout-button v-if="address.isDefault == 0" type="primary" @click.native="setDefault(address.addressId)">设为默认</swipeout-button>
                <swipeout-button type="warn" @click.native="deleteAddress(address.addressId)">删除</swipeout-button>
              </div>
              <div slot="content">
                <div style="display: table-cell;" v-if="address.isDefault == 1">
                  <img style="vertical-align: middle;height: 40px;" src="../../static/img/default.jpg"></img>
                </div>
                <div style="display: table-cell;" @click="comfireOrder(address.addressId)">
                  {{address.addressDetail}}
                </div>
                <div style="display: table-cell;vertical-align: middle">
                  <img src="../../static/img/update.png" @click="routerUpdate(address.addressId)"></img>
                </div>
              </div>
            </swipeout-item>
          </swipeout>
        </cell-box>
      </group>
    </div>
    <br/>
    <x-button type="primary" @click.native="addAddress()">添加地址</x-button>
  </div>
</template>
<script>
import { Group, Cell, CellBox, XButton, Swipeout, SwipeoutItem, SwipeoutButton } from 'vux'

export default {
  components: {
    Group,
    Cell,
    CellBox,
    XButton,
    Swipeout,
    SwipeoutItem,
    SwipeoutButton
  },
  data() {
    return {
      userId: window.localStorage["userId"],
      addressList: [],
      goodsId: this.$route.query.goodsId,
      goodsCount: this.$route.query.goodsCount
    }
  },
  mounted() {
    this.queryAddressList()
  },
  methods: {
    deleteAddress(addressId) {
      this.$tldAjax({
        isLayer: false,
        url: this.$domain + "/tld/admin/address/delete.json",
        params: {
          userId: this.userId,
          addressId: addressId
        },
        successFc: (response) => {
          this.queryAddressList()
        }
      });
    },
    setDefault(addressId) {
      this.$tldAjax({
        isLayer: false,
        url: this.$domain + "/tld/admin/address/setIsDefault.json",
        params: {
          userId: this.userId,
          addressId: addressId
        },
        successFc: (response) => {
          this.queryAddressList()
        }
      });
    },
    queryAddressList() {
      this.$tldAjax({
        isLayer: false,
        url: this.$domain + "/tld/admin/address/queryAddress.json",
        params: {
          userId: this.userId
        },
        successFc: (response) => {
          this.addressList = response.data.data
        }
      });
    },
    comfireOrder(addressId) {
      this.$router.push({
        path: '/tourl/comfireOrder',
        query: {
          addressId: addressId,
          goodsId: this.goodsId,
          goodsCount: this.goodsCount
        }
      })
    },
    routerUpdate(addressId) {
      this.$router.push({
        path: '/tourl/operateAddress',
        query: {
          addressId: addressId
        }
      })
    },
    addAddress() {
      this.$router.push({
        path: '/tourl/operateAddress',
        query: {
          addressId: '',
          goodsId: this.goodsId,
          goodsCount: this.goodsCount
        }
      })
    }
  }
}

</script>
